#include <stdio.h>
#include <dlfcn.h>
#include <signal.h>

extern long long _GLOBAL_OFFSET_TABLE_;
extern int add(int a, int b);

typedef int (*pFunc)(int a, int b);

void crackme(int sig) {
    void* handle = dlopen("./libmya2.so", RTLD_LAZY | RTLD_GLOBAL);
    pFunc newFunc = dlsym(handle, "new_add");
    long long * gotOfOld = (&_GLOBAL_OFFSET_TABLE_) + 9;
    printf("addr of got is %p\n", gotOfOld);
    printf("got is %p\n", (long long*)(*gotOfOld));
    printf("add is %p\n", add);
    printf("%d\n", newFunc(2, 2));
    *(gotOfOld) = (long long)newFunc;
}

int main() {
    int n;
    //signal(SIGUSR1, crackme);
    printf("before crack: %d\n", add(2, 2));
    crackme(0);
    printf("after crack: %d\n", add(2, 2));

    scanf("%d", &n);
    return 0;
}

